// 访问 token 缓存的 key
const ACCESS_TOKEN_KEY = "access_token";
// 刷新 token 缓存的 key
const REFRESH_TOKEN_KEY = "refresh_token";

// 获取token
const getToken = () => {
  return localStorage.getItem(ACCESS_TOKEN_KEY) || "";
};

// 设置token
const setToken = (token: string) => {
  localStorage.setItem(ACCESS_TOKEN_KEY, token);
};

// 设置刷新token
const setRefreshToken = (refreshToken: string) => {
  localStorage.setItem(REFRESH_TOKEN_KEY, refreshToken);
};

// 获取刷token
const getRefreshToken = () => {
  return localStorage.getItem(REFRESH_TOKEN_KEY);
};

// 清除 getToken
const clearToken = () => {
  localStorage.removeItem(ACCESS_TOKEN_KEY);
  localStorage.removeItem(REFRESH_TOKEN_KEY);
};

// 设置用户信息
const setUserInfo = (user: any) => {
  localStorage.setItem("userInfo", JSON.stringify(user));
};

// 获取用户信息
const getUserInfo = () => {
  return localStorage.getItem("userInfo");
};

const clearUserInfo = () => {
  localStorage.removeItem("userInfo");
};

export {
  clearToken,
  clearUserInfo,
  getRefreshToken,
  getToken,
  getUserInfo,
  setRefreshToken,
  setToken,
  setUserInfo,
};
